< previous page page_391 next page >

Page 391
ActiveForm is actually a property of the MDI (parent) form. Its purpose is similar to the Me keyword. ActiveForm refers to whichever MDI child form is currently active. By using the ActiveForm property in all code that resides in the MDI form, the code operates only on the active form and on no other. The following line of code provides a simple example of the ActiveForm property:
mdiMain.ActiveForm.Print "This form is currently active."
To test this code, place it in the Click event procedure of the MDI (parent) form. Make sure more than one child form is loaded. When an empty area of the parent is clicked, the text previously mentioned prints on whichever form is active.
note.gif Notice, here and in Listing 17.1, the use of the prefix mdi that was used when naming the MDI parent form. square.gif

Using the ActiveForm property, you can reference any property, method, or event of the currently active child form without having to know its name.
Initializing an Instance of a Child Form
If you need to write code that will be run when an instance of a child form is first created, you can place the code in the child form's Activate event procedure. The Activate event occurs as each new instance of the form is created, before the Load event occurs.
For example, you may want to set a child form's Caption property as the form is created. The sample project MDITest, available on the Web, contains code in the child form's Activate event procedure that increments a public variable to keep track of how many child form instances have been created and then sets the new form's Caption property to reflect that number.
Working with Menus
In Chapter 6, "Giving More Control to the User: Menus and Toolbars," you learned how to create a menu for your application. You also found out that you can have a different menu for each form in your program, if you so desire. MDI forms can also have menus. You create a menu for your MDI form the same way that you create a menu for a standard form, using the Menu Editor. The menu for the MDI form is usually the primary means by which you access the capabilities of an MDI application.
sarrow.gifSee "Creating a Menu Bar," p. 108
In an MDI application, the child forms can also have menus. As you do with the menu for the MDI form itself, you create child form menus by using the Menu Editor. However, when a child form that has a menu is displayed, its menu is not displayed as part of the child form but is displayed on the menu bar of the MDI form. This behavior presents a problem in your MDI applications because the MDI child form's menu actually replaces the MDI parent form's menu when the child is active. You cannot access the parent form's menu functions while the child form is active.

 
< previous page page_391 next page >